package com.pcafs.manage.controller;


import com.pcafs.common.annotation.Log;
import com.pcafs.common.core.controller.BaseController;
import com.pcafs.common.core.domain.AjaxResult;
import com.pcafs.common.core.page.TableDataInfo;
import com.pcafs.common.enums.BusinessType;
import com.pcafs.common.utils.poi.ExcelUtil;
import com.pcafs.manage.bo.ParentInfoAddBo;
import com.pcafs.manage.bo.ParentInfoEditBo;
import com.pcafs.manage.bo.ParentInfoQueryBo;
import com.pcafs.manage.service.IParentInfoService;
import com.pcafs.manage.vo.ParentInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 父母信息Controller
 * 
 * @author pcafs
 * @date 2021-05-05
 */
@Api(value = "父母信息控制器", tags = {"父母信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/manage/parentinfo")
public class ParentInfoController extends BaseController {

    private final IParentInfoService iParentInfoService;

    /**
     * 查询父母信息列表
     */
    @ApiOperation("查询父母信息列表")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:list')")
    @GetMapping("/list")
    public TableDataInfo<ParentInfoVo> list(ParentInfoQueryBo bo) {
        startPage();
        List<ParentInfoVo> list = iParentInfoService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出父母信息列表
     */
    @ApiOperation("导出父母信息列表")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:export')")
    @Log(title = "父母信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ParentInfoVo> export(ParentInfoQueryBo bo) {
        List<ParentInfoVo> list = iParentInfoService.queryList(bo);
        ExcelUtil<ParentInfoVo> util = new ExcelUtil<ParentInfoVo>(ParentInfoVo.class);
        return util.exportExcel(list, "父母信息");
    }

    /**
     * 获取父母信息详细信息
     */
    @ApiOperation("获取父母信息详细信息")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<ParentInfoVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iParentInfoService.queryById(id));
    }

    /**
     * 新增父母信息
     */
    @ApiOperation("新增父母信息")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:add')")
    @Log(title = "父母信息", businessType = BusinessType.INSERT)
    @PutMapping("save")
    public AjaxResult<Void> add(@RequestBody ParentInfoAddBo bo) {
        return toAjax(iParentInfoService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改父母信息
     */
    @ApiOperation("修改父母信息")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:edit')")
    @Log(title = "父母信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody ParentInfoEditBo bo) {
        return toAjax(iParentInfoService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除父母信息
     */
    @ApiOperation("删除父母信息")
    @PreAuthorize("@ss.hasPermi('manage:parentinfo:remove')")
    @Log(title = "父母信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iParentInfoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
